package com.itheima.controller;


import com.itheima.pojo.AdminOder;
import com.itheima.pojo.AdminOderQueryParam;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.service.AdminOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/orders")
public class AdminOrderController {
    @Autowired
    private AdminOrderService adminOrderService;

    @GetMapping("/list")
    public Result list() {
        log.info("查询订单列表");
        List<AdminOder> lists = adminOrderService.list();
        return Result.success(lists);
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        log.info(id.toString());
        AdminOder adminOder = adminOrderService.getById(id);
        return Result.success(adminOder);
    }

    @PutMapping
    public Result update(@RequestBody AdminOder adminOder) {
        log.info("修改订单{}", adminOder);
        adminOrderService.update(adminOder);
        return Result.success();
    }

    @GetMapping
    public Result page(AdminOderQueryParam param) {
        log.info(param.toString());
        PageBean page = adminOrderService.page(param);
        return Result.success(page);
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("删除订单{}", id);
        adminOrderService.delete(id);
        return Result.success();
    }


}
